import { CHANGE_RECOMMEND_LIST, CHANGE_BANNER_LIST } from "./constants"
import axios from "axios"

export const changeBannerListAction = (bannerList) => ({
  type: CHANGE_BANNER_LIST,
  bannerList
})

// 原来代码
export const changeRecommendListAction = (recommendList) => ({
  type: CHANGE_RECOMMEND_LIST,
  recommendList
})

// 加上异步后
export const fetchDataListAction = () => {
  return function thunkFn(dispatch, getState) {
    console.log("thunkFn log")
    const url = "http://123.207.32.32:8000/home/multidata"
    axios.get(url).then((res) => {
      if (res.status === 200 && res.statusText === "OK") {
        const data = res.data.data
        const { banner, recommend } = data
        console.log(banner.list, recommend.list, "changeRecommendListAction")
        dispatch(changeRecommendListAction(recommend.list))
        dispatch(changeBannerListAction(banner.list))
      }
    })
  }
}
